//
//  HomeViewController.swift
//  SinaProject
//
//  Created by 吴学宇 on 16/4/8.
//  Copyright © 2016年 吴学宇. All rights reserved.
//

import UIKit

class HomeViewController: BaseViewController {

    
    var titleButton : TitleButton?
    
   
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        setupNav();
        
        
    }
    
    // MARK - 导航条
   private func setupNav(){
    // 1.初始化左右按钮
    navigationItem.leftBarButtonItem = UIBarButtonItem.createBarButtonItem("navigationbar_friendattention", target: self, action: #selector(HomeViewController.leftItemClick))
    navigationItem.rightBarButtonItem = UIBarButtonItem.createBarButtonItem("navigationbar_pop", target: self, action: #selector(HomeViewController.rightItemClick));
  
    let titleButton = TitleButton();
    
    titleButton.setTitle("吴学宇", forState: UIControlState.Normal);
    titleButton.addTarget(self, action: #selector(titilButtonDidClicked), forControlEvents: UIControlEvents.TouchUpInside);
    
    self.titleButton = titleButton;
  
    navigationItem.titleView = titleButton;
        
    
    }
    
    func titilButtonDidClicked() -> Void {
    
        self.titleButton?.selected = !self.titleButton!.selected;
        
        let  pover = UIStoryboard(name: "PoverView", bundle: nil);
        let poverController = pover.instantiateInitialViewController();
        
        poverController?.transitioningDelegate =  poverAn;
        
        poverController?.modalPresentationStyle = UIModalPresentationStyle.Custom;
        presentViewController(poverController!, animated:true, completion: nil);
        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func leftItemClick(){
        
        
        
    }
    
    func rightItemClick(){
        
        
        let qrCode  = UIStoryboard(name: "QRCode", bundle: nil);
        
        let controller = qrCode.instantiateInitialViewController();
        
         presentViewController(controller!, animated: true, completion: nil)
        
        
        
    }
    
    
    private lazy var poverAn : poverAnimated = {
        
        let pover = poverAnimated();
        
        return pover;
        
     
    }()
    

  
}




